<!-- Begin: cppage - Create Ad -->
<div class="cppage createad">
    <div class="header">
        <?
        $disabled = '';
        if (CPanel::$vehicle_ad == null):
            ?>
            <h2>Cadastrar um novo anúncio</h2>
            <?
        else:
            $disabled = ' disabled';
            ?>
            <h2>Alterar anúncio</h2>
        <? endif ?>
    </div>
    <div class="alert-msg">Caro usuário, toda alteração realizado no anúncio será verificada por nossa equipe, caso seja constatada alguma irregularidade seu anúncio poderá ser bloqueado sem prévio aviso!</div>
    <form id="createad">
        <? if (CPanel::$account->a_type == 'F'): ?>
            <div class="plan">
                <label>Plano* :</label>
                <select class="input required<?= $disabled ?>" name="plan"<?= $disabled ?> title="Plano">
                    <option></option>
                    <?
                    $disabled = ' disabled';
                    foreach (DbGet::plans('F') as $plan):
                        if (CPanel::$vehicle_ad->id_plan == $plan->id):
                            ?>
                            <option value="<?= $plan->id ?>" selected><?= $plan->name ?></option>
                        <? else: ?>
                            <option value="<?= $plan->id ?>"><?= $plan->name ?></option>
                        <?
                        endif;
                    endforeach
                    ?>
                </select>
            </div>
        <? endif ?>
        <h2>Dados do veículo</h2>
        <div class="type">
            <label>Tipo* :</label>
            <select class="input required<?= $disabled ?>" name="type"<?= $disabled ?> title="Tipo">
                <option></option>
                <?
                if (CPanel::$vehicle_ad != null || CPanel::$account->a_type == 'J'):
                    if (isset(CPanel::$account->id_plan))
                        $id_plan = CPanel::$account->id_plan;
                    elseif (isset(CPanel::$vehicle_ad->id_plan))
                        $id_plan = CPanel::$vehicle_ad->id_plan;
                    else
                        $id_plan = null;
                    foreach (DbGet::plan_types($id_plan) as $type):
                        if ($type = DbGet::types($type->id_type)):
                            if (CPanel::$vehicle_ad->id_type == $type->id):
                                ?>
                                <option value="<?= $type->id ?>" selected><?= $type->name ?></option>
                            <? else: ?>
                                <option value="<?= $type->id ?>"><?= $type->name ?></option>
                            <?
                            endif;
                        endif;
                    endforeach;
                endif;
                ?>
            </select>
        </div>
        <div class="brand">
            <label>Marca* :</label>
            <select class="input required disabled" name="brand" disabled title="Marca">
                <option></option>
                <?
                if (CPanel::$vehicle_ad != null):
                    foreach (DbGet::brands(CPanel::$vehicle_ad->id_type) as $brand):
                        if (CPanel::$vehicle_ad->id_brand == $brand->id):
                            ?>
                            <option value="<?= $brand->id ?>" selected><?= $brand->name ?></option>
                        <? else: ?>
                            <option value="<?= $brand->id ?>"><?= $brand->name ?></option>
                        <?
                        endif;
                    endforeach;
                endif
                ?>
            </select>
        </div>
        <div class="model">
            <label>Modelo* :</label>
            <select class="input required disabled" name="model" disabled title="Modelo">
                <option></option>
                <?
                if (CPanel::$vehicle_ad != null):
                    foreach (DbGet::models(CPanel::$vehicle_ad->id_type, CPanel::$vehicle_ad->id_brand) as $model):
                        if (CPanel::$vehicle_ad->m_id == $model->id):
                            ?>
                            <option value="<?= $model->id ?>" selected><?= $model->name ?></option>
                        <? else: ?>
                            <option value="<?= $model->id ?>"><?= $model->name ?></option>
                        <?
                        endif;
                    endforeach;
                endif
                ?>
            </select>
        </div>
        <div class="version">
            <label>Versão:</label>
            <select class="input required disabled" name="version" disabled title="Versão">
                <option></option>
                <?
                if (CPanel::$vehicle_ad != null):
                    foreach (DbGet::modelsversion(CPanel::$vehicle_ad->id_version) as $version):
                        if (CPanel::$vehicle_ad->id_version == $version->id):
                            ?>
                            <option value="<?= $version->id ?>" selected><?= $version->name ?></option>
                        <? else: ?>
                            <option value="<?= $version->id ?>"><?= $version->name ?></option>
                        <?
                        endif;
                    endforeach;
                endif
                ?>
            </select>
        </div>
        <div class="engine">
            <label>Motor:</label>
            <input class="input" type="text" name="engine" maxlength="30" value="<?= CPanel::$vehicle_ad->engine ?>" title="Motor">
        </div>
        <div class="firstreg">
            <label>Ano de Fabricação* :</label>
            <select class="input required" name="firstreg" title="Ano de Fabricação">
                <option></option>
                <?
                for ($year = date('Y') + 1; $year >= 1930; $year--):
                    if (CPanel::$vehicle_ad->firstreg == $year):
                        ?>
                        <option selected><?= $year ?></option>
                    <? else: ?>
                        <option><?= $year ?></option>
                    <?
                    endif;
                endfor
                ?>
            </select>
        </div>
        <div class="modelyear">
            <label>Ano do Modelo* :</label>
            <select class="input required" name="modelyear" title="Ano do Modelo">
                <option></option>
                <?
                for ($year = date('Y') + 1; $year >= 1930; $year--):
                    if (CPanel::$vehicle_ad->modelyear == $year):
                        ?>
                        <option selected><?= $year ?></option>
                    <? else: ?>
                        <option><?= $year ?></option>
                    <?
                    endif;
                endfor
                ?>
            </select>
        </div>
        <div class="renavam">
            <label>RENAVAM:</label>
            <input class="input" type="text" name="renavam" value="<?= CPanel::$vehicle_ad->renavam ?>" title="RENAVAM">
        </div>
        <div class="owner">
            <label>Proprietário:</label>
            <input class="input" type="text" name="owner" maxlength="50" value="<?= CPanel::$vehicle_ad->owner ?>" title="Proprietário">
        </div>
        <div class="cpfcnpj_owner">
            <label>CPF/CNPJ do Proprietário:</label>
            <input class="input" type="text" name="cpfcnpj_owner" value="<?= CPanel::$vehicle_ad->cpfcnpj_owner ?>" title="CPF/CNPJ do Proprietário">
        </div>
        <h2>Valores</h2>
        <div class="price">
            <label>Preço* :</label>
            <input class="input required" type="text" name="price" maxlength="21" value="<?= Util::format_money(CPanel::$vehicle_ad->price) ?>" title="Preço">
        </div>
        <div class="discount">
            <label>Desconto:</label>
            <input class="input" type="text" name="discount" maxlength="21" value="<?= Util::format_money(CPanel::$vehicle_ad->discount) ?>" title="Desconto">
        </div>
        <div class="totalprice">
            <label>Preço Total:</label>
            <input class="input disabled" type="text" name="totalprice" disabled maxlength="21">
        </div>
        <div class="price-analysis">
            <h3>Análise de preço</h3>
            <p class="large">Selecione o tipo do veículo, marca, modelo, ano de fabricação e ano do modelo do veículo para uma análise de preço.</p>
            <p class="small">Preços de veículos semelhantes cadastrados em nosso sistema.</p>
            <p class="price media">
                <span>Média:</span>
                <span class="value">R$ 999.999.999.999,99</span>
            </p>
            <p class="price more">
                <span>Maior preço:</span>
                <span class="value">R$ 999.999.999.999,99</span>
            </p>
            <p class="price less">
                <span>Menor preço:</span>
                <span class="value">R$ 999.999.999.999,99</span>
            </p>
        </div>
        <fieldset class="financing">
            <legend>Financiado?</legend>
            <div class="funded radio">
                <?
                $radio[0] = $radio[1] = $disabled = '';
                if (CPanel::$vehicle_ad == null) {
                    $radio[0] = ' checked';
                    $disabled = ' disabled';
                } else {
                    $radio[CPanel::$vehicle_ad->funded] = ' checked';
                    if (!CPanel::$vehicle_ad->funded)
                        $disabled = ' disabled';
                }
                ?>
                <input type="radio" name="funded" value="1"<?= $radio[1] ?>><span>Sim</span>
                <input type="radio" name="funded" value="0"<?= $radio[0] ?>><span>Não</span>
            </div>
            <div class="inputvalue">
                <label>Entrada:</label>
                <input class="input<?= $disabled ?>" type="text" name="inputvalue"<?= $disabled ?> maxlength="21" value="<?= Util::format_money(CPanel::$vehicle_ad->inputvalue) ?>" title="Entrada">
            </div>
            <div class="parcelsquantity">
                <label>Parcelas:</label>
                <input class="input<?= $disabled ?>" type="text" name="parcelsquantity"<?= $disabled ?> value="<?= CPanel::$vehicle_ad->parcelsquantity ?>" title="Parcelas">
            </div>
            <div class="parcelvalue">
                <label>Valor das Parcelas:</label>
                <input class="input<?= $disabled ?>" type="text" name="parcelvalue"<?= $disabled ?> maxlength="21" value="<?= Util::format_money(CPanel::$vehicle_ad->parcelvalue) ?>" title="Valor das Parcelas">
            </div>
        </fieldset>
        <h2>Informações do veículo</h2>
        <div class="new radio">
            <label>Este veículo é zero KM?</label>
            <?
            $radio[0] = $radio[1] = '';
            if (CPanel::$vehicle_ad == null)
                $radio[0] = ' checked';
            else
                $radio[CPanel::$vehicle_ad->new] = ' checked';
            ?>
            <input type="radio" name="new" value="1"<?= $radio[1] ?>><span>Sim</span>
            <input type="radio" name="new" value="0"<?= $radio[0] ?>><span>Não</span>
        </div>
        <div class="fuel">
            <label>Combustível:</label>
            <select class="input" name="fuel" title="Combustível">
                <option></option>
                <?
                foreach (DbGet::fuels() as $fuel):
                    if (CPanel::$vehicle_ad->id_fuel == $fuel->id):
                        ?>
                        <option value="<?= $fuel->id ?>" selected><?= $fuel->name ?></option>
                    <? else: ?>
                        <option value="<?= $fuel->id ?>"><?= $fuel->name ?></option>
                    <?
                    endif;
                endforeach
                ?>
            </select>
        </div>
        <div class="color">
            <label>Cor* :</label>
            <select class="input required" name="color" title="Cor">
                <option></option>
                <?
                foreach (DbGet::colors() as $color):
                    if (CPanel::$vehicle_ad->id_color == $color->id):
                        ?>
                        <option value="<?= $color->id ?>" selected><?= $color->name ?></option>
                    <? else: ?>
                        <option value="<?= $color->id ?>"><?= $color->name ?></option>
                    <?
                    endif;
                endforeach
                ?>
            </select>
        </div>
        <div class="doors">
            <label>Portas:</label>
            <select class="input" name="doors" title="Portas">
                <option></option>

                <?
                for ($door = 2; $door <= 4; $door++):
                    if (CPanel::$vehicle_ad->doors == $door):
                        ?>
                        <option selected><?= $door ?></option>
                    <? else: ?>
                        <option><?= $door ?></option>
                    <?
                    endif;
                endfor
                ?>
            </select>
        </div>
        <div class="shield">
            <label>Blindagem:</label>
            <select class="input" name="shield" title="Blindagem">
                <option></option>
                <?
                foreach (DbGet::shields() as $shield):
                    if (CPanel::$vehicle_ad->id_shield == $shield->id):
                        ?>
                        <option value="<?= $shield->id ?>" selected><?= $shield->name ?></option>
                    <? else: ?>
                        <option value="<?= $shield->id ?>"><?= $shield->name ?></option>
                    <?
                    endif;
                endforeach
                ?>
            </select>
        </div>
        <div class="exchange">
            <label>Câmbio:</label>
            <select class="input" name="exchange" title="Câmbio">
                <option></option>
                <?
                foreach (DbGet::exchanges() as $exchange):
                    if (CPanel::$vehicle_ad->id_exchange == $exchange->id):
                        ?>
                        <option value="<?= $exchange->id ?>" selected><?= $exchange->name ?></option>
                    <? else: ?>
                        <option value="<?= $exchange->id ?>"><?= $exchange->name ?></option>
                    <?
                    endif;
                endforeach
                ?>
            </select>
        </div>
        <div class="plate">
            <label>Placa:</label>
            <input class="input" type="text" name="plate" value="<?= CPanel::$vehicle_ad->plate ?>" title="Placa">
        </div>
        <div class="km">
            <label>Quilometragem:</label>
            <input class="input" type="text" name="km" value="<?= CPanel::$vehicle_ad->km ?>" title="Quilometragem">
        </div>
        <div class="details"<?= isset(CPanel::$vehicle_ad->id_type) ? ' style="display: block"' : '' ?>>
            <h2>Detalhes do veículo</h2>
            <div class="radio">
                <?
                if (isset(CPanel::$vehicle_ad->id_type)):
                    $iddetails = array();
                    foreach (DbGet::vehicle_details(CPanel::$vehicle_ad->v_id) as $detail)
                        $iddetails[] = $detail->id_detail;
                    foreach (DbGet::details(CPanel::$vehicle_ad->id_type) as $detail):
                        ?>
                        <input type="checkbox" name="details[]" value="<?= $detail->id ?>"<?= in_array($detail->id, $iddetails) ? ' checked' : '' ?>>
                        <span><?= $detail->name ?></span>
                        <?
                    endforeach;
                endif
                ?>
            </div>
        </div>
        <div class="differentials">
            <h2>Diferenciais do veículo</h2>
            <div class="radio">
                <?
                $iddifferentials = array();
                if (isset(CPanel::$vehicle_ad->v_id))
                    foreach (DbGet::vehicle_differentials(CPanel::$vehicle_ad->v_id) as $differential)
                        $iddifferentials[] = $differential->id_differential;
                foreach (DbGet::differentials() as $differential):
                    ?>
                    <input type="checkbox" name="differentials[]" value="<?= $differential->id ?>"<?= in_array($differential->id, $iddifferentials) ? ' checked' : '' ?>>
                    <span><?= $differential->name ?></span>
                <? endforeach ?>
            </div>
        </div>
        <div class="differentials">
            <h2>Observações</h2>
            <textarea name="observations" id="observations" class="observations"><?= CPanel::$vehicle_ad->observations ?></textarea>
        </div>
        <h2>Multimédia</h2>
        <ul class="pictures">
            <p>As fotos devem seguir o padrão do site, caso contrário o anúncio não será liberado (saiba qual o padrão <a href="javascript:;">clicando aqui</a>).</p>
            <?
            if (CPanel::$vehicle_ad != null):
                $pictures = DbGet::vehicle_pictures(CPanel::$vehicle_ad->v_id);
                ?>
                <input type="hidden" name="pictures-excluded">
            <? endif ?>
            <li>
                <? if (!isset($pictures[0])): ?>
                    <img src="<?= _IMG_ ?>photo-diagonal-front1.jpg" alt="Foto Diagonal Frontal" />
                    <input type="file" name="pictures[]">
                <? else: ?>
                    <img src="<?= _VHC_IMG_ . 'last-updated/' . $pictures[0]->filename ?>" data-original="<?= _IMG_ ?>photo-front.jpg" alt="Foto Dianteira" />
                    <input type="file" name="pictures[]" disabled>
                    <a class="del" href="javascript:;" data="<?= $pictures[0]->id ?>"></a>
                <? endif ?>
            </li>
            <li>
                <? if (!isset($pictures[1])): ?>
                    <img src="<?= _IMG_ ?>photo-front.jpg" alt="Foto Frontal" />
                    <input type="file" name="pictures[]">
                <? else: ?>
                    <img src="<?= _VHC_IMG_ . 'last-updated/' . $pictures[1]->filename ?>" data-original="<?= _IMG_ ?>photo-side.jpg" alt="Foto Dianteira" />
                    <input type="file" name="pictures[]" disabled>
                    <a class="del" href="javascript:;" data="<?= $pictures[1]->id ?>"></a>
                <? endif ?>
            </li>
            <li>
                <? if (!isset($pictures[2])): ?>
                    <img src="<?= _IMG_ ?>photo-back.jpg" alt="Foto Traseira" />
                    <input type="file" name="pictures[]">
                <? else: ?>
                    <img src="<?= _VHC_IMG_ . 'last-updated/' . $pictures[2]->filename ?>" data-original="<?= _IMG_ ?>photo-back.jpg" alt="Foto Dianteira" />
                    <input type="file" name="pictures[]" disabled>
                    <a class="del" href="javascript:;" data="<?= $pictures[2]->id ?>"></a>
                <? endif ?>
            </li>
            <li>
                <? if (!isset($pictures[3])): ?>
                    <img src="<?= _IMG_ ?>photo-diagonal-back1.jpg" alt="Foto Diagonal Traseira" />
                    <input type="file" name="pictures[]">
                <? else: ?>
                    <img src="<?= _VHC_IMG_ . 'last-updated/' . $pictures[3]->filename ?>" data-original="<?= _IMG_ ?>photo-interior.jpg" alt="Foto Dianteira" />
                    <input type="file" name="pictures[]" disabled>
                    <a class="del" href="javascript:;" data="<?= $pictures[3]->id ?>"></a>
                <? endif ?>
            </li>
            <li>
                <? if (!isset($pictures[4])): ?>
                    <img src="<?= _IMG_ ?>photo-panel.jpg" alt="Foto Painel" />
                    <input type="file" name="pictures[]">
                <? else: ?>
                    <img src="<?= _VHC_IMG_ . 'last-updated/' . $pictures[4]->filename ?>" data-original="<?= _IMG_ ?>photo-motor.jpg" alt="Foto Dianteira" />
                    <input type="file" name="pictures[]" disabled>
                    <a class="del" href="javascript:;" data="<?= $pictures[4]->id ?>"></a>
                <? endif ?>
            </li>
            <li>
                <? if (!isset($pictures[5])): ?>
                    <img src="<?= _IMG_ ?>photo-back-seat.jpg" alt="Foto Banco Traseiro" />
                    <input type="file" name="pictures[]">
                <? else: ?>
                    <img src="<?= _VHC_IMG_ . 'last-updated/' . $pictures[5]->filename ?>" data-original="<?= _IMG_ ?>photo-front.jpg" alt="Foto" />
                    <input type="file" name="pictures[]" disabled>
                    <a class="del" href="javascript:;" data="<?= $pictures[5]->id ?>"></a>
                <? endif ?>
            </li>
            <li>
                <? if (!isset($pictures[6])): ?>
                    <img src="<?= _IMG_ ?>photo-motor.jpg" alt="Foto Motor" />
                    <input type="file" name="pictures[]">
                <? else: ?>
                    <img src="<?= _VHC_IMG_ . 'last-updated/' . $pictures[6]->filename ?>" data-original="<?= _IMG_ ?>photo-front.jpg" alt="Foto" />
                    <input type="file" name="pictures[]" disabled>
                    <a class="del" href="javascript:;" data="<?= $pictures[6]->id ?>"></a>
                <? endif ?>
            </li>
            <li>
                <? if (!isset($pictures[7])): ?>
                    <img src="<?= _IMG_ ?>photo-wheel.jpg" alt="Foto Roda/Pneu" />
                    <input type="file" name="pictures[]">
                <? else: ?>
                    <img src="<?= _VHC_IMG_ . 'last-updated/' . $pictures[7]->filename ?>" data-original="<?= _IMG_ ?>photo-front.jpg" alt="Foto" />
                    <input type="file" name="pictures[]" disabled>
                    <a class="del" href="javascript:;" data="<?= $pictures[7]->id ?>"></a>
                <? endif ?>
            </li>
            <li>
                <? if (!isset($pictures[8])): ?>
                    <img src="<?= _IMG_ ?>photo-trunk.jpg" alt="Foto Porta Mala" />
                    <input type="file" name="pictures[]">
                <? else: ?>
                    <img src="<?= _VHC_IMG_ . 'last-updated/' . $pictures[8]->filename ?>" data-original="<?= _IMG_ ?>photo-front.jpg" alt="Foto" />
                    <input type="file" name="pictures[]" disabled>
                    <a class="del" href="javascript:;" data="<?= $pictures[8]->id ?>"></a>
                <? endif ?>
            </li>
            <li>
                <? if (!isset($pictures[9])): ?>
                    <img src="<?= _IMG_ ?>photo-headlamp.jpg" alt="Foto Lanterna/Farol" />
                    <input type="file" name="pictures[]">
                <? else: ?>
                    <img src="<?= _VHC_IMG_ . 'last-updated/' . $pictures[9]->filename ?>" data-original="<?= _IMG_ ?>photo-front.jpg" alt="Foto" />
                    <input type="file" name="pictures[]" disabled>
                    <a class="del" href="javascript:;" data="<?= $pictures[9]->id ?>"></a>
                <? endif ?>
            </li>
            <li>
                <? if (!isset($pictures[10])): ?>
                    <img src="<?= _IMG_ ?>photo-diagonal-front2.jpg" alt="Foto Diagonal Frontal 2" />
                    <input type="file" name="pictures[]">
                <? else: ?>
                    <img src="<?= _VHC_IMG_ . 'last-updated/' . $pictures[10]->filename ?>" data-original="<?= _IMG_ ?>photo-front.jpg" alt="Foto" />
                    <input type="file" name="pictures[]" disabled>
                    <a class="del" href="javascript:;" data="<?= $pictures[10]->id ?>"></a>
                <? endif ?>
            </li>
            <li>
                <? if (!isset($pictures[11])): ?>
                    <img src="<?= _IMG_ ?>photo-diagonal-back2.jpg" alt="Foto Diagonal Traseira 2" />
                    <input type="file" name="pictures[]">
                <? else: ?>
                    <img src="<?= _VHC_IMG_ . 'last-updated/' . $pictures[11]->filename ?>" data-original="<?= _IMG_ ?>photo-front.jpg" alt="Foto" />
                    <input type="file" name="pictures[]" disabled>
                    <a class="del" href="javascript:;" data="<?= $pictures[11]->id ?>"></a>
                <? endif ?>
            </li>
        </ul>
        <!--
        <div class="video">
            <label>Adicione um vídeo ao anúncio:</label>
            <input class="input" type="text" name="video" maxlength="50">
        </div>
        -->
        <h2>Contrato</h2>
        <div class="use-agreement">
            <label>Contrato de utilização do site Goiautos:</label>
            <div class="terms"><?= DbGet::miscellaneous('use_agreement') ?></div>
            <div class="terms-accepted">
                <input type="checkbox" name="terms_accepted">
                <span>Li e aceito os termos descritos acima</span>
            </div>
        </div>
        <input type="hidden" name="cpanel" value="createad">
        <? if (CPanel::$vehicle_ad != null): ?>
            <input type="hidden" name="id" value="<?= CPanel::$vehicle_ad->v_id ?>">
        <? endif ?>
        <input class="submit" type="submit" value="Salvar">
    </form>
</div> <!-- End -->
